<template>
  <!-- 放置一个图标 -->
  <div>
    <svg-icon :icon-class="isFullscreen ? 'exit-fullscreen' : 'fullscreen'" class="fullscreen" @click="screenFn" />
  </div>
</template>

<script>
// 引入插件screenfull
import screenFull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      isFullscreen: false // 全屏状态
    }
  },
  created() {
    screenFull.on('change', () => {
      // console.log(screenFull.isFullscreen)
      this.isFullscreen = screenFull.isFullscreen // 将是否全屏的状态赋值给data变量,让svg根据变量的状态切换
    })
  },
  methods: {
    screenFn() {
      if (screenFull.isEnabled) {
        screenFull.toggle()
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
